<template>
  <div class="login_conter">
    <div class="loginBox">
      <div class="login_img">
        <img src="../assets/logo@2x.png" alt="" />
      </div>
      <el-form  :model="loginForm" :rules="loginRules" ref="loginFormRef" label-position="right"  class="elForm">
        <el-form-item label="账户" prop="username">
          <el-input v-model="loginForm.username" prefix-icon="el-icon-user" placeholder="请输入用户账号" minlength="3" maxlength="11"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input type="password" v-model="loginForm.password" prefix-icon="el-icon-lock" placeholder="请输入账户密码" minlength="3" maxlength="15"></el-input>
        </el-form-item>
        <el-form-item  class="btns">
             <el-button type="primary" @click="login">登录</el-button>
             <el-button type="info" @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div> 
</template>
<script>
export default {
  data() {
    return {
        loginForm:{
            username:"",
            password:"",
            type:"1"
        },
        loginRules:{
            userName: [
                { required: true, message: '请输入用户账号', trigger: 'blur' },
                { min: 3, max: 11, message: '长度在3到11个字符', trigger: 'blur' }
            ],
            password: [
                { required: true, message: '请输入账户密码', trigger: 'blur' },
                { min: 3, max: 15, message: '长度在3到15个字符', trigger: 'blur' }
            ],
        }
    };
  },
  methods: {
      resetForm(){//重置表单
          this.$refs.loginFormRef.resetFields()
      },
      login(){//注册 validate 验证表单 {username:this.username,password:this.password},
        // console.log(this.$store.state.msg)
        // this.$store.commit('meThods')
        // console.log(this.$store.state.msg)
        // console.log(window.navigator.userAgent);
        // console.log(window.navigator.platform);
        this.$refs.loginFormRef.validate(async (valid) => {
            if (!valid) return
            const { data: res } = await this.$http.post('currencyAudit/loginValue',this.httputil(this.loginForm))
            if (res.code !== 200) return this.$message.error(res.msg)
            this.$message.success(res.msg)
            // 1. 将登录成功之后的 token，保存到客户端的 sessionStorage 中
            //   1.1 项目中出了登录之外的其他API接口，必须在登录之后才能访问
            //   1.2 token 只应在当前网站打开期间生效，所以将 token 保存在 sessionStorage 中
            window.sessionStorage.setItem('token', this.loginForm.password)
            // window.sessionStorage.setItem('token', 123)
            // 2. 通过编程式导航跳转到后台主页，路由地址是 /home
            this.$router.push('/home')
        })
      }
  },
};
</script>
<style lang="less" scoped>
.login_conter {
  background: #f49e39;
  width: 100%;
  height: 100%;
  .loginBox {
    position: absolute;
    width: 400px;
    height: 360px;
    background: #fff;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: -1px 1px 5px #f3f3f3;
    border-radius: 10px;
    .login_img {
      width: 120px;
      height: 120px;
      border-radius: 50%;
      position: absolute;
      left: 50%;
      transform: translate(-50%, -50%);
      background: #fff;
      border: 1px solid #f1f1f1;
      padding: 5px;
      box-shadow: -1px 1px 5px #f3f3f3;
      img {
        width: 100%;
        border-radius: 50%;

        border: 1px solid #f1f1f1;
      }
    }
  }
  .elForm{
    position: absolute;
    bottom: 0;
    width: 100%;
    box-sizing: border-box;
    padding: 0 20px;
  }
  .btns{
    display: flex;
    justify-content: flex-end;
  }
}
.el-form-item__label{
    padding: 0;
}
.el-form--label-top{
    padding: 0;
}
</style>
